#pragma once

#include <mutex>
#include <mysql/mysql.h>
#include "logger.h"
#include <string>
using std::string;
using std::lock_guard;
using std::mutex;
class MySQLConnector
{
public:
    MySQLConnector & operator=(const MySQLConnector& conn) = delete;
    MySQLConnector(const MySQLConnector & conn)= delete;
    static MySQLConnector * getInstance();
    static void destory();
    void query(const string & sql);
    bool execute(const string & sql);
    bool connect(const string & localhost, 
                 const string & username,
                 const string &password,
                 const string &database);
    static MYSQL_RES * getResult();
private:
    static MySQLConnector *_pinstance;
    static mutex _mux;
    static MYSQL *_conn;
    static MYSQL_RES *_result;
    
    MySQLConnector();
    ~MySQLConnector();
};
